package com.kyb.servlet;

import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.kyb.dao.IDepartmentDao;
import com.kyb.dao.IUserDao;
import com.kyb.impl.DepartmentDaoImpl;
import com.kyb.impl.UserDaoImpl;

/**
 * 
    * @ClassName: BackJsonServlet
    * @Description: 返回给第三方平台需要的json信息
    * @author 刘照峰
    * @date 2018年8月28日-下午3:19:06
 */
@WebServlet("/backJson")
public class BackJsonServlet extends HttpServlet{

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json; charset=utf-8");
		response.setCharacterEncoding("UTF-8");
 
		IUserDao user = new UserDaoImpl();
		IDepartmentDao dept = new DepartmentDaoImpl();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("userList", user.getAllUser());
		map.put("deptList", dept.getAllDept());
		
		String userJson = JSON.toJSONString(map);
		OutputStream out = response.getOutputStream();
		out.write(userJson.getBytes("UTF-8"));
		out.flush();
	}
 
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	
}
